﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using YJTMedicalAideManage.Cores.ApiModel;
using YJTMedicalAideManage.Cores.Events;
using YJTMedicalAideManage.Cores.Globals;
using YJTMedicalAideManage.Cores.PusApiModel;
using YJTMedicalAideManage.Cores.Servers;

namespace YJTMedicalAideManage.MAM.Model
{
    public class MAMDto : INotifyPropertyChanged
    {
        private string keywords;
        private string status;
        private string? beginDate;
        private string? endDate;
        private string id;
        private string scale;
        private string operatorId;
        private string name;
        private string username;
        private string tel;
        private string address;
        private string tenantName;
        private string tenantId;
        private string liveProvinceId;
        private string liveCityId;
        private string liveAreaId;
        private string wechatDoctorOpenid;
        private string retDoctor;
        private string createTime;
        private string substatus;
        private string tooltip;
        private bool isStateCheckedstatus;
        private Visibility visibility;
        private List<string> statusList = new List<string>();

        public event PropertyChangedEventHandler PropertyChanged;
        public string page { get; set; }

        public string limit { get; set; }
        public string Status
        {
            get { return status; }
            set
            {
                if (status != value)
                {
                    status = value;
                    OnPropertyChanged(nameof(Status));
                    if (value == "0")
                    {
                        IsStateCheckedstatus = true;
                    }
                    else
                    {
                        IsStateCheckedstatus = false;
                    }
                }
            }
        }
        public Visibility Visibility
        {
            get { return visibility; }
            set
            {
                if (visibility != value)
                {
                    visibility = value;
                    OnPropertyChanged(nameof(Visibility));
                }
            }
        }
        public string Substatus
        {
            get { return substatus; }
            set
            {
                if (substatus != value)
                {
                    substatus = value;
                    OnPropertyChanged(nameof(Substatus));
                }
            }
        }
        public bool IsStateCheckedstatus
        {
            get { return isStateCheckedstatus; }
            set
            {
                if (isStateCheckedstatus != value)
                {
                    isStateCheckedstatus = value;
                    OnPropertyChanged(nameof(IsStateCheckedstatus));
                    GlobalApp.Instance.OperatorId = OperatorId;
                }
            }
        }
        public string Keywords
        {
            get { return keywords; }
            set
            {
                if (keywords != value)
                {
                    keywords = value;
                    OnPropertyChanged(nameof(Keywords));
                }
            }
        }
        public List<string> StatusList
        {
            get => statusList;
            set
            {
                if (statusList != value)
                {
                    statusList = value;
                    OnPropertyChanged(nameof(StatusList));
                }
            }
        }
        public string Id
        {
            get { return id; }
            set
            {
                if (id != value)
                {
                    id = value;
                    OnPropertyChanged(nameof(Id));
                }
            }
        }

        public string Scale
        {
            get { return scale; }
            set
            {
                if (scale != value)
                {
                    scale = value;
                    OnPropertyChanged(nameof(Scale));
                }
            }
        }

        public string OperatorId
        {
            get { return operatorId; }
            set
            {
                if (operatorId != value)
                {
                    operatorId = value;
                    OnPropertyChanged(nameof(OperatorId));
                }
            }
        }

        public string Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    name = value;
                    OnPropertyChanged(nameof(Name));
                }
            }
        }

        public string Username
        {
            get { return username; }
            set
            {
                if (username != value)
                {
                    username = value;
                    OnPropertyChanged(nameof(Username));
                }
            }
        }

        public string Tel
        {
            get { return tel; }
            set
            {
                if (tel != value)
                {
                    tel = value;
                    OnPropertyChanged(nameof(Tel));
                }
            }
        }

        public string Address
        {
            get { return address; }
            set
            {
                if (address != value)
                {
                    address = value;
                    OnPropertyChanged(nameof(Address));
                }
            }
        }
        public string Tooltip
        {
            get { return tooltip; }
            set
            {
                if (tooltip != value)
                {
                    tooltip = value;
                    OnPropertyChanged(nameof(Tooltip));
                }
            }
        }

        public string TenantName
        {
            get { return tenantName; }
            set
            {
                if (tenantName != value)
                {
                    tenantName = value;
                    OnPropertyChanged(nameof(TenantName));
                }
            }
        }

        public string TenantId
        {
            get { return tenantId; }
            set
            {
                if (tenantId != value)
                {
                    tenantId = value;
                    OnPropertyChanged(nameof(TenantId));
                }
            }
        }

        public string LiveProvinceId
        {
            get { return liveProvinceId; }
            set
            {
                if (liveProvinceId != value)
                {
                    liveProvinceId = value;
                    OnPropertyChanged(nameof(LiveProvinceId));
                }
            }
        }

        public string LiveCityId
        {
            get { return liveCityId; }
            set
            {
                if (liveCityId != value)
                {
                    liveCityId = value;
                    OnPropertyChanged(nameof(LiveCityId));
                }
            }
        }

        public string LiveAreaId
        {
            get { return liveAreaId; }
            set
            {
                if (liveAreaId != value)
                {
                    liveAreaId = value;
                    OnPropertyChanged(nameof(LiveAreaId));
                }
            }
        }

        public string WechatDoctorOpenid
        {
            get { return wechatDoctorOpenid; }
            set
            {
                if (wechatDoctorOpenid != value)
                {
                    wechatDoctorOpenid = value;
                    OnPropertyChanged(nameof(WechatDoctorOpenid));
                }
            }
        }

        public string RetDoctor
        {
            get { return retDoctor; }
            set
            {
                if (retDoctor != value)
                {
                    retDoctor = value;
                    OnPropertyChanged(nameof(RetDoctor));
                }
            }
        }

        public string? BeginDate
        {
            get { return beginDate; }
            set
            {
                if (beginDate != value)
                {
                    beginDate = value;
                    OnPropertyChanged(nameof(BeginDate));
                }
            }
        }

        public string? EndDate
        {
            get { return endDate; }
            set
            {
                if (endDate != value)
                {
                    endDate = value;
                    OnPropertyChanged(nameof(EndDate));
                }
            }
        }

        public string CreateTime
        {
            get { return createTime; }
            set
            {
                if (createTime != value)
                {
                    createTime = value;
                    OnPropertyChanged(nameof(CreateTime));
                }
            }
        }
        public string Pwd { get; set; }
        public string Live_address { get; set; }
        public MAMDto MapAssToMAMDto(ass ass)
        {
            return new MAMDto
            {  Live_address = ass.live_address,
                Status = ass.status,
                Id = ass.id,
                OperatorId = ass.operator_id,
                Name = ass.name,
                Username = ass.username,
                Tel = ass.tel,
                Address = ass.address,
                TenantName = ass.tenant_name,
                TenantId = ass.tenant_id,
                LiveProvinceId = ass.live_province_id,
                LiveCityId = ass.live_city_id,
                LiveAreaId = ass.live_area_id,
                WechatDoctorOpenid = ass.wechat_doctor_openid,
                CreateTime = ass.create_time,
                RetDoctor = ass.ret_doctor,
                Pwd = ass.password
            };
        }
        public assinit MAMDtoToassinit()
        {
            return new assinit
            {
                status = StatusCov(Status),
                keywords = Keywords == null ? "" :Keywords ,
                begin_date = BeginDate==null ? "": BeginDate,
                end_date = EndDate == null ? "" : EndDate,
                page = page,
                limit = limit
            };
        }
        private string StatusCov(string str) 
        {
            switch (str)
            {
                case"全部":
                    return "";
                case "启用":
                    return "0";
                case "停用":
                    return "-1";
            }
            return "";
        }
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

}
